package com.spring.demo.init.db;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.spring.demo.core.dao.IMemberDao;
import com.spring.demo.core.dao.jdbc.MemberDao;
import com.spring.demo.core.service.IMemberService;
import com.spring.demo.core.service.impl.MemberService;

/**
 * 测试声明式事务
 * 
 * @author sean
 * 
 */
@Configuration
@EnableTransactionManagement
public class DeclarativeTransactionConfig extends EmbeddedDataSource {

	@Bean(name = "dataSourceTransactionManager")
	@Autowired
	public DataSourceTransactionManager dataSourceTransactionManager(
			@Qualifier("embeddedDataSource") DataSource dataSource) {
		DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(
				dataSource);

		return transactionManager;
	}

	@Bean
	public IMemberService memberService() {
		return new MemberService();
	}

	@Bean
	public IMemberDao memberDao() {
		return new MemberDao();
	}
}
